package demo9;

/**
 * 二叉树中的深搜_验证二叉搜索树
 * https://leetcode.cn/problems/validate-binary-search-tree/
 */

class Solution {
    long prev = Long.MIN_VALUE;
    public boolean isValidBST(TreeNode root) {
        // 出口
        if(root == null) return true;
        boolean ret = true;
        ret &= isValidBST(root.left);
        // 剪枝
        if(ret == false) return false;
        // 剪枝
        if(root.val <= prev) return false;

        prev = root.val;
        if(root.right != null) ret &= isValidBST(root.right);
        return ret;
    }
}